package com.bj58.migrate.condition.impl;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;

public class PostdateCondition extends AbstractCondition{

    private boolean continuous = true;
    private String start = "20140101";
    private String end = "20150101";

    public PostdateCondition(){
        intConditionList();
    }

    public PostdateCondition( String start, String end, boolean continuous ){

        this.start = start;
        this.end = end;
        this.continuous = continuous;

        intConditionList();
    }

    @Override
    public void intConditionList(){

        if( continuous ){
            conlist.add( "postdate=" + start + "_" + end );
        }
        else{
            Calendar start = new GregorianCalendar( 2013, 05, 01, 0, 0, 0 );
            Calendar end = new GregorianCalendar( 2014, 00, 16, 0, 0, 0 );

            SimpleDateFormat format = new SimpleDateFormat( "yyyyMMdd" );

            try{
                while( start.before( end ) ){
                    String date = format.format( start.getTime() );
                    conlist.add( "postdate=" + date + "_" + date );
                    start.add( Calendar.DAY_OF_MONTH, +1 );
                }
            }
            catch( Exception ex ){
                ex.printStackTrace();
            }
        }
    }
}
